<!DOCTYPE html>
<!-- saved from url=(0064)http://yannesposito.com/Scratch/en/blog/Learn-Vim-Progressively/ -->
<html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        
        <title>YBlog - Learn Vim Progressively</title>
        <meta name="keywords" content="vi, vim, editor, tutorial, learn">

        <link rel="shortcut icon" type="image/x-icon" href="http://yannesposito.com/Scratch/img/favicon.ico">
        <link rel="stylesheet" type="text/css" href="./YBlog - Learn Vim Progressively_files/scientific.css">
        <link rel="stylesheet" type="text/css" href="./YBlog - Learn Vim Progressively_files/solarized_light.css">
        <link rel="stylesheet" type="text/css" href="./YBlog - Learn Vim Progressively_files/solarized.css">
		<!-- Font -->
        <link href="./YBlog - Learn Vim Progressively_files/css" rel="stylesheet" type="text/css">
        <link rel="alternate" type="application/rss+xml" title="RSS" href="http://feeds.feedburner.com/yannespositocomen">
        <!--[if lt IE 9]>
        <script src="http://ie7-js.googlecode.com/svn/version/2.1(beta4)/IE9.js"></script>
        <![endif]-->

    <script type="text/javascript" async="" src="http://yannesposito.disqus.com/embed.js"></script><style type="text/css">.MathJax_Hover_Frame {border-radius: .25em; -webkit-border-radius: .25em; -moz-border-radius: .25em; -khtml-border-radius: .25em; box-shadow: 0px 0px 15px #83A; -webkit-box-shadow: 0px 0px 15px #83A; -moz-box-shadow: 0px 0px 15px #83A; -khtml-box-shadow: 0px 0px 15px #83A; border: 1px solid #A6D ! important; display: inline-block; position: absolute}
.MathJax_Menu_Button .MathJax_Hover_Arrow {position: absolute; cursor: pointer; display: inline-block; border: 2px solid #AAA; border-radius: 4px; -webkit-border-radius: 4px; -moz-border-radius: 4px; -khtml-border-radius: 4px; font-family: 'Courier New',Courier; font-size: 9px; color: #F0F0F0}
.MathJax_Menu_Button .MathJax_Hover_Arrow span {display: block; background-color: #AAA; border: 1px solid; border-radius: 3px; line-height: 0; padding: 4px}
.MathJax_Hover_Arrow:hover {color: white!important; border: 2px solid #CCC!important}
.MathJax_Hover_Arrow:hover span {background-color: #CCC!important}
</style><style type="text/css">#MathJax_About {position: fixed; left: 50%; width: auto; text-align: center; border: 3px outset; padding: 1em 2em; background-color: #DDDDDD; color: black; cursor: default; font-family: message-box; font-size: 120%; font-style: normal; text-indent: 0; text-transform: none; line-height: normal; letter-spacing: normal; word-spacing: normal; word-wrap: normal; white-space: nowrap; float: none; z-index: 201; border-radius: 15px; -webkit-border-radius: 15px; -moz-border-radius: 15px; -khtml-border-radius: 15px; box-shadow: 0px 10px 20px #808080; -webkit-box-shadow: 0px 10px 20px #808080; -moz-box-shadow: 0px 10px 20px #808080; -khtml-box-shadow: 0px 10px 20px #808080; filter: progid:DXImageTransform.Microsoft.dropshadow(OffX=2, OffY=2, Color='gray', Positive='true')}
#MathJax_About.MathJax_MousePost {outline: none}
.MathJax_Menu {position: absolute; background-color: white; color: black; width: auto; padding: 2px; border: 1px solid #CCCCCC; margin: 0; cursor: default; font: menu; text-align: left; text-indent: 0; text-transform: none; line-height: normal; letter-spacing: normal; word-spacing: normal; word-wrap: normal; white-space: nowrap; float: none; z-index: 201; box-shadow: 0px 10px 20px #808080; -webkit-box-shadow: 0px 10px 20px #808080; -moz-box-shadow: 0px 10px 20px #808080; -khtml-box-shadow: 0px 10px 20px #808080; filter: progid:DXImageTransform.Microsoft.dropshadow(OffX=2, OffY=2, Color='gray', Positive='true')}
.MathJax_MenuItem {padding: 2px 2em; background: transparent}
.MathJax_MenuArrow {position: absolute; right: .5em; padding-top: .25em; color: #666666; font-size: .75em}
.MathJax_MenuActive .MathJax_MenuArrow {color: white}
.MathJax_MenuArrow.RTL {left: .5em; right: auto}
.MathJax_MenuCheck {position: absolute; left: .7em}
.MathJax_MenuCheck.RTL {right: .7em; left: auto}
.MathJax_MenuRadioCheck {position: absolute; left: 1em}
.MathJax_MenuRadioCheck.RTL {right: 1em; left: auto}
.MathJax_MenuLabel {padding: 2px 2em 4px 1.33em; font-style: italic}
.MathJax_MenuRule {border-top: 1px solid #CCCCCC; margin: 4px 1px 0px}
.MathJax_MenuDisabled {color: GrayText}
.MathJax_MenuActive {background-color: Highlight; color: HighlightText}
.MathJax_MenuDisabled:focus, .MathJax_MenuLabel:focus {background-color: #E8E8E8}
.MathJax_ContextMenu:focus {outline: none}
.MathJax_ContextMenu .MathJax_MenuItem:focus {outline: none}
#MathJax_AboutClose {top: .2em; right: .2em}
.MathJax_Menu .MathJax_MenuClose {top: -10px; left: -10px}
.MathJax_MenuClose {position: absolute; cursor: pointer; display: inline-block; border: 2px solid #AAA; border-radius: 18px; -webkit-border-radius: 18px; -moz-border-radius: 18px; -khtml-border-radius: 18px; font-family: 'Courier New',Courier; font-size: 24px; color: #F0F0F0}
.MathJax_MenuClose span {display: block; background-color: #AAA; border: 1.5px solid; border-radius: 18px; -webkit-border-radius: 18px; -moz-border-radius: 18px; -khtml-border-radius: 18px; line-height: 0; padding: 8px 0 6px}
.MathJax_MenuClose:hover {color: white!important; border: 2px solid #CCC!important}
.MathJax_MenuClose:hover span {background-color: #CCC!important}
.MathJax_MenuClose:hover:focus {outline: none}
</style><style type="text/css">.MathJax_Preview .MJXf-math {color: inherit!important}
</style><style type="text/css">.MJX_Assistive_MathML {position: absolute!important; top: 0; left: 0; clip: rect(1px, 1px, 1px, 1px); padding: 1px 0 0 0!important; border: 0!important; height: 1px!important; width: 1px!important; overflow: hidden!important; display: block!important; -webkit-touch-callout: none; -webkit-user-select: none; -khtml-user-select: none; -moz-user-select: none; -ms-user-select: none; user-select: none}
.MJX_Assistive_MathML.MJX_Assistive_MathML_Block {width: 100%!important}
</style><style type="text/css">#MathJax_Zoom {position: absolute; background-color: #F0F0F0; overflow: auto; display: block; z-index: 301; padding: .5em; border: 1px solid black; margin: 0; font-weight: normal; font-style: normal; text-align: left; text-indent: 0; text-transform: none; line-height: normal; letter-spacing: normal; word-spacing: normal; word-wrap: normal; white-space: nowrap; float: none; -webkit-box-sizing: content-box; -moz-box-sizing: content-box; box-sizing: content-box; box-shadow: 5px 5px 15px #AAAAAA; -webkit-box-shadow: 5px 5px 15px #AAAAAA; -moz-box-shadow: 5px 5px 15px #AAAAAA; -khtml-box-shadow: 5px 5px 15px #AAAAAA; filter: progid:DXImageTransform.Microsoft.dropshadow(OffX=2, OffY=2, Color='gray', Positive='true')}
#MathJax_ZoomOverlay {position: absolute; left: 0; top: 0; z-index: 300; display: inline-block; width: 100%; height: 100%; border: 0; padding: 0; margin: 0; background-color: white; opacity: 0; filter: alpha(opacity=0)}
#MathJax_ZoomFrame {position: relative; display: inline-block; height: 0; width: 0}
#MathJax_ZoomEventTrap {position: absolute; left: 0; top: 0; z-index: 302; display: inline-block; border: 0; padding: 0; margin: 0; background-color: white; opacity: 0; filter: alpha(opacity=0)}
</style><style type="text/css">.MathJax_Preview {color: #888}
#MathJax_Message {position: fixed; left: 1em; bottom: 1.5em; background-color: #E6E6E6; border: 1px solid #959595; margin: 0px; padding: 2px 8px; z-index: 102; color: black; font-size: 80%; width: auto; white-space: nowrap}
#MathJax_MSIE_Frame {position: absolute; top: 0; left: 0; width: 0px; z-index: 101; border: 0px; margin: 0px; padding: 0px}
.MathJax_Error {color: #CC0000; font-style: italic}
</style><style type="text/css">.MJXp-script {font-size: .8em}
.MJXp-right {-webkit-transform-origin: right; -moz-transform-origin: right; -ms-transform-origin: right; -o-transform-origin: right; transform-origin: right}
.MJXp-bold {font-weight: bold}
.MJXp-italic {font-style: italic}
.MJXp-scr {font-family: MathJax_Script,'Times New Roman',Times,STIXGeneral,serif}
.MJXp-frak {font-family: MathJax_Fraktur,'Times New Roman',Times,STIXGeneral,serif}
.MJXp-sf {font-family: MathJax_SansSerif,'Times New Roman',Times,STIXGeneral,serif}
.MJXp-cal {font-family: MathJax_Caligraphic,'Times New Roman',Times,STIXGeneral,serif}
.MJXp-mono {font-family: MathJax_Typewriter,'Times New Roman',Times,STIXGeneral,serif}
.MJXp-largeop {font-size: 150%}
.MJXp-largeop.MJXp-int {vertical-align: -.2em}
.MJXp-math {display: inline-block; line-height: 1.2; text-indent: 0; font-family: 'Times New Roman',Times,STIXGeneral,serif; white-space: nowrap; border-collapse: collapse}
.MJXp-display {display: block; text-align: center; margin: 1em 0}
.MJXp-math span {display: inline-block}
.MJXp-box {display: block!important; text-align: center}
.MJXp-box:after {content: " "}
.MJXp-rule {display: block!important; margin-top: .1em}
.MJXp-char {display: block!important}
.MJXp-mo {margin: 0 .15em}
.MJXp-mfrac {margin: 0 .125em; vertical-align: .25em}
.MJXp-denom {display: inline-table!important; width: 100%}
.MJXp-denom > * {display: table-row!important}
.MJXp-surd {vertical-align: top}
.MJXp-surd > * {display: block!important}
.MJXp-script-box > *  {display: table!important; height: 50%}
.MJXp-script-box > * > * {display: table-cell!important; vertical-align: top}
.MJXp-script-box > *:last-child > * {vertical-align: bottom}
.MJXp-script-box > * > * > * {display: block!important}
.MJXp-mphantom {visibility: hidden}
.MJXp-munderover {display: inline-table!important}
.MJXp-over {display: inline-block!important; text-align: center}
.MJXp-over > * {display: block!important}
.MJXp-munderover > * {display: table-row!important}
.MJXp-mtable {vertical-align: .25em; margin: 0 .125em}
.MJXp-mtable > * {display: inline-table!important; vertical-align: middle}
.MJXp-mtr {display: table-row!important}
.MJXp-mtd {display: table-cell!important; text-align: center; padding: .5em 0 0 .5em}
.MJXp-mtr > .MJXp-mtd:first-child {padding-left: 0}
.MJXp-mtr:first-child > .MJXp-mtd {padding-top: 0}
.MJXp-mlabeledtr {display: table-row!important}
.MJXp-mlabeledtr > .MJXp-mtd:first-child {padding-left: 0}
.MJXp-mlabeledtr:first-child > .MJXp-mtd {padding-top: 0}
.MJXp-merror {background-color: #FFFF88; color: #CC0000; border: 1px solid #CC0000; padding: 1px 3px; font-style: normal; font-size: 90%}
.MJXp-scale0 {-webkit-transform: scaleX(.0); -moz-transform: scaleX(.0); -ms-transform: scaleX(.0); -o-transform: scaleX(.0); transform: scaleX(.0)}
.MJXp-scale1 {-webkit-transform: scaleX(.1); -moz-transform: scaleX(.1); -ms-transform: scaleX(.1); -o-transform: scaleX(.1); transform: scaleX(.1)}
.MJXp-scale2 {-webkit-transform: scaleX(.2); -moz-transform: scaleX(.2); -ms-transform: scaleX(.2); -o-transform: scaleX(.2); transform: scaleX(.2)}
.MJXp-scale3 {-webkit-transform: scaleX(.3); -moz-transform: scaleX(.3); -ms-transform: scaleX(.3); -o-transform: scaleX(.3); transform: scaleX(.3)}
.MJXp-scale4 {-webkit-transform: scaleX(.4); -moz-transform: scaleX(.4); -ms-transform: scaleX(.4); -o-transform: scaleX(.4); transform: scaleX(.4)}
.MJXp-scale5 {-webkit-transform: scaleX(.5); -moz-transform: scaleX(.5); -ms-transform: scaleX(.5); -o-transform: scaleX(.5); transform: scaleX(.5)}
.MJXp-scale6 {-webkit-transform: scaleX(.6); -moz-transform: scaleX(.6); -ms-transform: scaleX(.6); -o-transform: scaleX(.6); transform: scaleX(.6)}
.MJXp-scale7 {-webkit-transform: scaleX(.7); -moz-transform: scaleX(.7); -ms-transform: scaleX(.7); -o-transform: scaleX(.7); transform: scaleX(.7)}
.MJXp-scale8 {-webkit-transform: scaleX(.8); -moz-transform: scaleX(.8); -ms-transform: scaleX(.8); -o-transform: scaleX(.8); transform: scaleX(.8)}
.MJXp-scale9 {-webkit-transform: scaleX(.9); -moz-transform: scaleX(.9); -ms-transform: scaleX(.9); -o-transform: scaleX(.9); transform: scaleX(.9)}
.MathJax_PHTML .noError {vertical-align: ; font-size: 90%; text-align: left; color: black; padding: 1px 3px; border: 1px solid}
</style></head>
    <body lang="en" class="article"><div id="MathJax_Message" style="display: none;"></div>
        <div id="content">
	        			<div id="header">
			    <div id="choix">
        	        <div id="choixlang">
                        <a href="http://yannesposito.com/Scratch/fr/blog/Learn-Vim-Progressively/">French</a> 
        	        </div>
					<div id="switchcss"><a href="http://yannesposito.com/Scratch/en/blog/Learn-Vim-Progressively/#">Change Theme</a></div>
                    <div class="tomenu"><a href="http://yannesposito.com/Scratch/en/blog/Learn-Vim-Progressively/#navigation">↓ Menu ↓</a></div>
        	        <div class="flush"></div>
        	    </div>
			</div>

			<div id="titre">
				<h1>Learn Vim Progressively</h1>
				
			</div>
			<div class="flush"></div>
      <div id="afterheader" class="article">
          <div class="corps">
              <div>
<img src="./YBlog - Learn Vim Progressively_files/uber_leet_use_vim.jpg" alt="Über leet use vim!">
</div>
<div class="intro">
<p><span class="sc"><abbr title="Too long; didn&#39;t read">tl;dr</abbr>: </span> You want to teach yourself vim (the best text editor known to human kind) in the fastest way possible. This is my way of doing it. You start by learning the minimal to survive, then you integrate all the tricks slowly.</p>
</div>
<p><a href="http://www.vim.org/">Vim</a> the Six Billion Dollar editor</p>
<blockquote>
<p>Better, Stronger, Faster.</p>
</blockquote>
<p>Learn <a href="http://www.vim.org/">vim</a> and it will be your last text editor. There isn’t any better text editor that I know of. It is hard to learn, but incredible to use.</p>
<p>I suggest you teach yourself Vim in 4 steps:</p>
<ol type="1">
<li>Survive</li>
<li>Feel comfortable</li>
<li>Feel Better, Stronger, Faster</li>
<li>Use superpowers of vim</li>
</ol>
<p>By the end of this journey, you’ll become a vim superstar.</p>
<p>But before we start, just a warning. Learning vim will be painful at first. It will take time. It will be a lot like playing a musical instrument. Don’t expect to be more efficient with vim than with another editor in less than 3 days. In fact it will certainly take 2 weeks instead of 3 days.</p>
<h2 id="st-level-survive">1st Level – Survive</h2>
<ol start="0" type="1">
<li>Install <a href="http://www.vim.org/">vim</a></li>
<li>Launch vim</li>
<li>DO NOTHING! Read.</li>
</ol>
<p>In a standard editor, typing on the keyboard is enough to write something and see it on the screen. Not this time. Vim is in <em>Normal</em> mode. Let’s go to <em>Insert</em> mode. Type the letter <code>i</code>.</p>
<p>You should feel a bit better. You can type letters like in a standard editor. To get back to <em>Normal</em> mode just press the <code>ESC</code> key.</p>
<p>You now know how to switch between <em>Insert</em> and <em>Normal</em> mode. And now, here are the commands that you need in order to survive in <em>Normal</em> mode:</p>
<blockquote>
<ul>
<li><code>i</code> → <em>Insert</em> mode. Type <code>ESC</code> to return to Normal mode.</li>
<li><code>x</code> → Delete the char under the cursor</li>
<li><code>:wq</code> → Save and Quit (<code>:w</code> save, <code>:q</code> quit)</li>
<li><code>dd</code> → Delete (and copy) the current line</li>
<li><code>p</code> → Paste</li>
</ul>
<p>Recommended:</p>
<ul>
<li><code>hjkl</code> (highly recommended but not mandatory) → basic cursor move (←↓↑→). Hint: <code>j</code> looks like a down arrow.</li>
<li><code>:help &lt;command&gt;</code> → Show help about <code>&lt;command&gt;</code>. You can use <code>:help</code> without a <code>&lt;command&gt;</code> to get general help.</li>
</ul>
</blockquote>
<p>Only 5 commands. That is all you need to get started. Once these command start to become natural (maybe after a day or so), you should move on to level 2.</p>
<p>But first, just a little remark about <em>Normal mode</em>. In standard editors, to copy you have to use the <code>Ctrl</code> key (<code>Ctrl-c</code> generally). In fact, when you press <code>Ctrl</code>, it is as if all of your keys change meaning. Using vim in normal mode is a bit like having the editor automatically press the <code>Ctrl</code> key for you.</p>
<p>A last word about notations:</p>
<ul>
<li>instead of writing <code>Ctrl-λ</code>, I’ll write <code>&lt;C-λ&gt;</code>.</li>
<li>commands starting with <code>:</code> end with <code>&lt;enter&gt;</code>. For example, when I write <code>:q</code>, I mean <code>:q&lt;enter&gt;</code>.</li>
</ul>
<h2 id="nd-level-feel-comfortable">2nd Level – Feel comfortable</h2>
<p>You know the commands required for survival. It’s time to learn a few more commands. These are my suggestions:</p>
<ol type="1">
<li><p>Insert mode variations:</p>
<blockquote>
<ul>
<li><code>a</code> → insert after the cursor</li>
<li><code>o</code> → insert a new line after the current one</li>
<li><code>O</code> → insert a new line before the current one</li>
<li><code>cw</code> → replace from the cursor to the end of the word</li>
</ul>
</blockquote></li>
<li><p>Basic moves</p>
<blockquote>
<ul>
<li><code>0</code> → go to the first column</li>
<li><code>^</code> → go to the first non-blank character of the line</li>
<li><code>$</code> → go to the end of line</li>
<li><code>g_</code> → go to the last non-blank character of line</li>
<li><code>/pattern</code> → search for <code>pattern</code></li>
</ul>
</blockquote></li>
<li><p>Copy/Paste</p>
<blockquote>
<ul>
<li><code>P</code> → paste before, remember <code>p</code> is paste after current position.</li>
<li><code>yy</code> → copy the current line, easier but equivalent to <code>ddP</code></li>
</ul>
</blockquote></li>
<li><p>Undo/Redo</p>
<blockquote>
<ul>
<li><code>u</code> → undo</li>
<li><code>&lt;C-r&gt;</code> → redo</li>
</ul>
</blockquote></li>
<li><p>Load/Save/Quit/Change File (Buffer)</p>
<blockquote>
<ul>
<li><code>:e &lt;path/to/file&gt;</code> → open</li>
<li><code>:w</code> → save</li>
<li><code>:saveas &lt;path/to/file&gt;</code> → save to <code>&lt;path/to/file&gt;</code></li>
<li><code>:x</code>, <code>ZZ</code> or <code>:wq</code> → save and quit (<code>:x</code> only save if necessary)</li>
<li><code>:q!</code> → quit without saving, also: <code>:qa!</code> to quit even if there are modified hidden buffers.</li>
<li><code>:bn</code> (resp. <code>:bp</code>) → show next (resp. previous) file (buffer)</li>
</ul>
</blockquote></li>
</ol>
<p>Take the time to learn all of these command. Once done, you should be able to do every thing you are able to do in other editors. You may still feel a bit awkward. But follow me to the next level and you’ll see why vim is worth the extra work.</p>
<h2 id="rd-level-better.-stronger.-faster.">3rd Level – Better. Stronger. Faster.</h2>
<p>Congratulation for reaching this far! Now we can start with the interesting stuff. At level 3, we’ll only talk about commands which are compatible with the old vi editor.</p>
<h3 id="better">Better</h3>
<p>Let’s look at how vim could help you to repeat yourself:</p>
<ol type="1">
<li><code>.</code> → (dot) will repeat the last command,</li>
<li>N&lt;command&gt; → will repeat the command N times.</li>
</ol>
<p>Some examples, open a file and type:</p>
<blockquote>
<ul>
<li><code>2dd</code> → will delete 2 lines</li>
<li><code>3p</code> → will paste the text 3 times</li>
<li><code>100idesu [ESC]</code> → will write “desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu”</li>
<li><code>.</code> → Just after the last command will write again the 100 “desu”.</li>
<li><code>3.</code> → Will write 3 “desu” (and not 300, how clever).</li>
</ul>
</blockquote>
<h3 id="stronger">Stronger</h3>
<p>Knowing how to move efficiently with vim is <em>very</em> important. Don’t skip this section.</p>
<ol type="1">
<li>N<code>G</code> → Go to line N</li>
<li><code>gg</code> → shortcut for <code>1G</code> - go to the start of the file</li>
<li><code>G</code> → Go to last line</li>
<li><p>Word moves:</p>
<blockquote>
<ol type="1">
<li><code>w</code> → go to the start of the following word,</li>
<li><code>e</code> → go to the end of this word.</li>
</ol>
<p>By default, words are composed of letters and the underscore character. Let’s call a WORD a group of letter separated by blank characters. If you want to consider WORDS, then just use uppercase characters:</p>
<ol type="1">
<li><code>W</code> → go to the start of the following WORD,</li>
<li><code>E</code> → go to the end of this WORD.</li>
</ol>
<div>
<img src="./YBlog - Learn Vim Progressively_files/word_moves.jpg" alt="Word moves example">
</div>
</blockquote></li>
</ol>
<p>Now let’s talk about very efficient moves:</p>
<blockquote>
<ul>
<li><code>%</code> : Go to the corresponding <code>(</code>, <code>{</code>, <code>[</code>.</li>
<li><code>*</code> (resp. <code>#</code>) : go to next (resp. previous) occurrence of the word under the cursor</li>
</ul>
</blockquote>
<p>Believe me, the last three commands are gold.</p>
<h3 id="faster">Faster</h3>
<p>Remember about the importance of vi moves? Here is the reason. Most commands can be used using the following general format:</p>
<p><code>&lt;start position&gt;&lt;command&gt;&lt;end position&gt;</code></p>
<p>For example : <code>0y$</code> means</p>
<ul>
<li><code>0</code> → go to the beginning of this line</li>
<li><code>y</code> → yank from here</li>
<li><code>$</code> → up to the end of this line</li>
</ul>
<p>We also can do things like <code>ye</code>, yank from here to the end of the word. But also <code>y2/foo</code> yank up to the second occurrence of “foo”.</p>
<p>But what was true for <code>y</code> (yank), is also true for <code>d</code> (delete), <code>v</code> (visual select), <code>gU</code> (uppercase), <code>gu</code> (lowercase), etc…</p>
<h2 id="th-level-vim-superpowers">4th Level – Vim Superpowers</h2>
<p>With all preceding commands you should be comfortable using vim. But now, here are the killer features. Some of these features were the reason I started to use vim.</p>
<h3 id="move-on-current-line-0-g_-f-f-t-t">Move on current line: <code>0</code> <code>^</code> <code>$</code> <code>g_</code> <code>f</code> <code>F</code> <code>t</code> <code>T</code> <code>,</code> <code>;</code></h3>
<blockquote>
<ul>
<li><code>0</code> → go to column 0</li>
<li><code>^</code> → go to first character on the line</li>
<li><code>$</code> → go to the last column</li>
<li><code>g_</code> → go to the last character on the line</li>
<li><code>fa</code> → go to next occurrence of the letter <code>a</code> on the line. <code>,</code> (resp. <code>;</code>) will find the next (resp. previous) occurrence.</li>
<li><code>t,</code> → go to just before the character <code>,</code>.</li>
<li><code>3fa</code> → find the 3rd occurrence of <code>a</code> on this line.</li>
<li><code>F</code> and <code>T</code> → like <code>f</code> and <code>t</code> but backward.
<div>
<img src="./YBlog - Learn Vim Progressively_files/line_moves.jpg" alt="Line moves">
</div></li>
</ul>
</blockquote>
<p>A useful tip is: <code>dt"</code> → remove everything until the <code>"</code>.</p>
<h3 id="zone-selection-actionaobject-or-actioniobject">Zone selection <code>&lt;action&gt;a&lt;object&gt;</code> or <code>&lt;action&gt;i&lt;object&gt;</code></h3>
<p>These command can only be used after an operator in visual mode. But they are very powerful. Their main pattern is:</p>
<p><code>&lt;action&gt;a&lt;object&gt;</code> and <code>&lt;action&gt;i&lt;object&gt;</code></p>
<p>Where action can be any action, for example, <code>d</code> (delete), <code>y</code> (yank), <code>v</code> (select in visual mode). The object can be: <code>w</code> a word, <code>W</code> a WORD (extended word), <code>s</code> a sentence, <code>p</code> a paragraph. But also, natural character such as <code>"</code>, <code>'</code>, <code>)</code>, <code>}</code>, <code>]</code>.</p>
<p>Suppose the cursor is on the first <code>o</code> of <code>(map (+) ("foo"))</code>.</p>
<blockquote>
<ul>
<li><code>vi"</code> → will select <code>foo</code>.</li>
<li><code>va"</code> → will select <code>"foo"</code>.</li>
<li><code>vi)</code> → will select <code>"foo"</code>.</li>
<li><code>va)</code> → will select <code>("foo")</code>.</li>
<li><code>v2i)</code> → will select <code>map (+) ("foo")</code></li>
<li><code>v2a)</code> → will select <code>(map (+) ("foo"))</code></li>
</ul>
</blockquote>
<div>
<img src="./YBlog - Learn Vim Progressively_files/textobjects.png" alt="Text objects selection">
</div>
<h3 id="select-rectangular-blocks-c-v.">Select rectangular blocks: <code>&lt;C-v&gt;</code>.</h3>
<p>Rectangular blocks are very useful for commenting many lines of code. Typically: <code>0&lt;C-v&gt;&lt;C-d&gt;I-- [ESC]</code></p>
<ul>
<li><code>^</code> → go to the first non-blank character of the line</li>
<li><code>&lt;C-v&gt;</code> → Start block selection</li>
<li><code>&lt;C-d&gt;</code> → move down (could also be <code>jjj</code> or <code>%</code>, etc…)</li>
<li><code>I-- [ESC]</code> → write <code>--</code> to comment each line</li>
</ul>
<div>
<img src="./YBlog - Learn Vim Progressively_files/rectangular-blocks.gif" alt="Rectangular blocks">
</div>
<p>Note: in Windows you might have to use <code>&lt;C-q&gt;</code> instead of <code>&lt;C-v&gt;</code> if your clipboard is not empty.</p>
<h3 id="completion-c-n-and-c-p.">Completion: <code>&lt;C-n&gt;</code> and <code>&lt;C-p&gt;</code>.</h3>
<p>In Insert mode, just type the start of a word, then type <code>&lt;C-p&gt;</code>, magic…</p>
<div>
<img src="./YBlog - Learn Vim Progressively_files/completion.gif" alt="Completion">
</div>
<h3 id="macros-qa-do-something-q-a">Macros : <code>qa</code> do something <code>q</code>, <code>@a</code>, <code>@@</code></h3>
<p><code>qa</code> record your actions in the <em>register</em> <code>a</code>. Then <code>@a</code> will replay the macro saved into the register <code>a</code> as if you typed it. <code>@@</code> is a shortcut to replay the last executed macro.</p>
<blockquote>
<p><em>Example</em></p>
<p>On a line containing only the number 1, type this:</p>
<ul>
<li><code>qaYp&lt;C-a&gt;q</code> →
<ul>
<li><code>qa</code> start recording.</li>
<li><code>Yp</code> duplicate this line.</li>
<li><code>&lt;C-a&gt;</code> increment the number.</li>
<li><code>q</code> stop recording.</li>
</ul></li>
<li><code>@a</code> → write 2 under the 1</li>
<li><code>@@</code> → write 3 under the 2</li>
<li>Now do <code>100@@</code> will create a list of increasing numbers until 103.</li>
</ul>
</blockquote>
<div>
<img src="./YBlog - Learn Vim Progressively_files/macros.gif" alt="Macros">
</div>
<h3 id="visual-selection-vvc-v">Visual selection: <code>v</code>,<code>V</code>,<code>&lt;C-v&gt;</code></h3>
<p>We saw an example with <code>&lt;C-v&gt;</code>. There is also <code>v</code> and <code>V</code>. Once the selection has been made, you can:</p>
<ul>
<li><code>J</code> → join all the lines together.</li>
<li><code>&lt;</code> (resp. <code>&gt;</code>) → indent to the left (resp. to the right).</li>
<li><code>=</code> → auto indent</li>
</ul>
<div>
<img src="./YBlog - Learn Vim Progressively_files/autoindent.gif" alt="Autoindent">
</div>
<p>Add something at the end of all visually selected lines:</p>
<ul>
<li><code>&lt;C-v&gt;</code></li>
<li>go to desired line (<code>jjj</code> or <code>&lt;C-d&gt;</code> or <code>/pattern</code> or <code>%</code> etc…)</li>
<li><code>$</code> go to the end of the line</li>
<li><code>A</code>, write text, <code>ESC</code>.</li>
</ul>
<div>
<img src="./YBlog - Learn Vim Progressively_files/append-to-many-lines.gif" alt="Append to many lines">
</div>
<h3 id="splits-split-and-vsplit.">Splits: <code>:split</code> and <code>vsplit</code>.</h3>
<p>These are the most important commands, but you should look at <code>:help split</code>.</p>
<blockquote>
<ul>
<li><code>:split</code> → create a split (<code>:vsplit</code> create a vertical split)</li>
<li><code>&lt;C-w&gt;&lt;dir&gt;</code> : where dir is any of <code>hjkl</code> or ←↓↑→ to change the split.</li>
<li><code>&lt;C-w&gt;_</code> (resp. <code>&lt;C-w&gt;|</code>) : maximise the size of the split (resp. vertical split)</li>
<li><code>&lt;C-w&gt;+</code> (resp. <code>&lt;C-w&gt;-</code>) : Grow (resp. shrink) split</li>
</ul>
</blockquote>
<div>
<img src="./YBlog - Learn Vim Progressively_files/split.gif" alt="Split">
</div>
<h2 id="conclusion">Conclusion</h2>
<p>That was 90% of the commands I use every day. I suggest that you learn no more than one or two new commands per day. After two to three weeks you’ll start to feel the power of vim in your hands.</p>
<p>Learning Vim is more a matter of training than plain memorization. Fortunately vim comes with some very good tools and excellent documentation. Run vimtutor until you are familiar with most basic commands. Also, you should read this page carefully: <code>:help usr_02.txt</code>.</p>
<p>Then, you will learn about <code>!</code>, folds, registers, plugins and many other features. Learn vim like you’d learn piano and all should be fine.</p>
<blockquote>
<p>If you liked this article, there is a follow up: <a href="http://yannesposito.com/Scratch/en/blog/Vim-as-IDE/"><em>Vim as IDE</em></a></p>
</blockquote>
<script>
// Style the keywords
$(document).ready(function() {
    $('code').css({ 'border': 'solid 1px #CCC', 'padding':'3px'});
});
</script>
          </div>
          <div id="afterarticle">
              <div id="social">
                  <a target="_blank" href="http://feeds.feedburner.com/yannespositocomen" class="social">r</a>
                  ·
                  <a target="_blank" href="https://twitter.com/home?status=http://yannesposito.com/Scratch/en/blog/Learn-Vim-Progressively/%20via%20@yogsototh" class="social">t</a>
                  ·
                  <a target="_blank" href="http://www.facebook.com/sharer/sharer.php?u=/Scratch/en/blog/Learn-Vim-Progressively/" class="social">`</a>
                  ·
                  <a target="_blank" href="https://plus.google.com/share?url=http://yannesposito.com/Scratch/en/blog/Learn-Vim-Progressively/" class="social">g</a>
                  <br>
                  <a class="message" href="http://yannesposito.com/Scratch/en/blog/Social-link-the-right-way/">These social sharing links preserve your privacy</a>
              </div>
              <div id="navigation">
                  <a href="http://yannesposito.com/">Home</a>
                  <span class="sep">¦</span>
                  <a href="http://yannesposito.com/Scratch/en/blog">Blog</a>
                  <span class="sep">¦</span>
                  <a href="http://yannesposito.com/Scratch/en/softwares">Softwares</a>
                  <span class="sep">¦</span>
                  <a href="http://yannesposito.com/Scratch/en/about">About</a>
              </div>
              <div id="totop"><a href="http://yannesposito.com/Scratch/en/blog/Learn-Vim-Progressively/#header">↑ Top ↑</a></div>
              <div class="corps" id="comment">
                  <h2 class="first">Comments</h2>
                  <div id="disqus_thread"></div>
                  <script type="text/javascript">
                   /* * * CONFIGURATION VARIABLES: EDIT BEFORE PASTING INTO YOUR WEBPAGE * * */
                   var disqus_shortname = 'yannesposito'; // required: replace example with your forum shortname
                   var disqus_identifier = '/Scratch/en/blog/Learn-Vim-Progressively/index.html';

                   /* * * DON'T EDIT BELOW THIS LINE * * */
                   (function() {
                       var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true;
                       dsq.src = 'http://' + disqus_shortname + '.disqus.com/embed.js';
                       (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
                   })();
                  </script>
                  <noscript>Please enable JavaScript to view the <a href="http://disqus.com/?ref_noscript">comments powered by Disqus.</a></noscript>
                  <a href="http://disqus.com/" class="dsq-brlink">comments powered by <span class="logo-disqus">Disqus</span></a>
              </div>
              <div class="tomenu"><a>↑ Menu ↑</a></div>
              <div id="bottom">
                  <div>
                      Published on 2011-08-25
                  </div>
                  <div>
                      <a href="https://twitter.com/yogsototh">Follow @yogsototh</a>
                  </div>
                  <div>
                      <a rel="license" href="http://creativecommons.org/licenses/by/3.0/deed.en_US">Yann Esposito©</a>
                  </div>

                  <div>
                      Done with
                      <a href="http://www.vim.org/" target="_blank"><span class="strike">Vim</span></a>
                      <a href="http://spacemacs.org/" target="_blank">spacemacs</a>
                      <span class="pala">&amp;</span>
                      <a href="http://nanoc.ws/" target="_blank"><span class="strike">nanoc</span></a>
                      <a href="http://jaspervdj.be/hakyll" target="_blank">Hakyll</a>
                  </div>
                  <hr>
                  <div>
                      <a href="https://cardanoexplorer.com/address/DdzFFzCqrhtAtYxakocsgjSK5pb6DWCVLPGuj2JMEC1FpAfBMfJCDAFpgZEPaitGKxCLWy1ViVkUWPzQbiJopPvLckoYoa8zPMb49egS">
                          <img src="./YBlog - Learn Vim Progressively_files/ada-logo.png" class="simple" style="height: 16px;
                                    border-radius: 50%;
                                    vertical-align:middle;
                                    display:inline-block;">
                          ADA:
                          <code style="display:inline-block;
                                       word-wrap:break-word;
                                       text-align: left;
                                       vertical-align: top;
                                       max-width: 85%;">
DdzFFzCqrhtAtYxakocsgjSK5pb6DWCVLPGuj2JMEC1FpAfBMfJCDAFpgZEPaitGKxCLWy1ViVkUWPzQbiJopPvLckoYoa8zPMb49egS
                          </code>
                      </a>
                  </div>
              </div>
          </div>
      </div>
      

        </div>
        <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.0/jquery.min.js"></script>
        <script>window.jQuery || document.write('<script src="/Scratch/js/vendor/jquery-1.10.0.min.js"><\/script>')</script><script src="./YBlog - Learn Vim Progressively_files/jquery-1.10.0.min.js.下载"></script>
        <script src="./YBlog - Learn Vim Progressively_files/jquery.scrolldepth.min.js.下载"></script>
        <script src="./YBlog - Learn Vim Progressively_files/jquery.cookie.js.下载"></script>
        <script src="./YBlog - Learn Vim Progressively_files/index.js.下载"></script>
        <script src="./YBlog - Learn Vim Progressively_files/highlight.pack.js.下载"></script>
        <script src="./YBlog - Learn Vim Progressively_files/article.js.下载"></script>
        <script src="./YBlog - Learn Vim Progressively_files/MathJax.js.下载" id=""></script>
    

</body></html>